package jvm.init;

/**
 * Created by IntelliJ IDEA.
 * User: liuliwei
 * Date: 2017-08-09
 * Time: 上午9:52
 * Description: ${description}
 */

public class InitTeST {

    public static void main(String[] args) {
//        test1();
        test2();
        test3();
        People[] p = new People[5];
        hold();

    }

    /**
     * 常量传播优化 直接进入常量池中
     */
    private static void test3() {
        System.out.println(People.finalFlag);
    }

    /**
     * 只初始化直接声明变量的类
     */
    private static void test2() {
        System.out.println(SubPeople.name);
    }

    private static void hold() {
        System.out.println("no use");
    }

    /**
     * 不初始化组件类型
     */
    private static void test1() {
        People[] people = new People[10];
    }


}


class People {
    public static String name = "people";
    public static final String finalFlag = "staticFlag";
    static{
        System.out.println("People init");
    }
    private int age;

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }
}

class SubPeople extends People {
    static{
        System.out.println("SubPeople init");
    }

}
